export const getImgElements = (elements) => {
  const imgElements = []
  elements.forEach((el) => {
    imgElements.push(...el.getElementsByTagName('img'))
  })
  return imgElements
}
export const getAllimgs = (imgElements) => {
  return imgElements.map((img) => {
    return img.src
  })
}

export const onComplateImgs = (images) => {
  const promiseAll = []
  images.forEach((src, index) => {
    promiseAll[index] = new Promise((resolve, reject) => {
      const imgObj = new Image()
      imgObj.src = src
      imgObj.onload = () => {
        resolve({
          index,
          src
        })
      }
      imgObj.onerror = () => {
        resolve({
          index,
          src
        })
      }
    })
  })
  return Promise.all(promiseAll)
}
// 获取最小高度所在的
export const getMinHeight = (columnHeightObj) => {
  return Math.min(...Object.values(columnHeightObj))
}
// 获取最大高度所在的列
export const getMaxHeight = (columnHeightObj) => {
  return Math.max(...Object.values(columnHeightObj))
}
// 获取最小高度的列
export const getMinHeightColumn = (columnHeightObj) => {
  const minHeight = getMinHeight(columnHeightObj)
  return Object.keys(columnHeightObj).find((key, index) => {
    return columnHeightObj[key] == minHeight
  })
}
